package com.cs.study.homework._0311.TestTCP;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {

        //4. 利用输入输出流进行读写操作
        //5. 释放资源


        //1. 创建服务端的socket对象(ServerSocket)
        ServerSocket serverSocket = new ServerSocket(4567);

        //2. 通过accept建立连接, 得到socket对象
        Socket socket = serverSocket.accept();

        //3. 从socket中得到输入输出流
        InputStream in = socket.getInputStream();
        FileOutputStream out = new FileOutputStream("E://a//b.txt");
        //利用输入流进行读写操作
        byte[] bytes = new byte[1024];
        int readCount = in.read(bytes);
        out.write(bytes,0,readCount);
        out.flush();
        out.close();
        socket.close();


    }
}
